Package org.python.pydev.refactoring.tests.ast.factory

Source Code of org.python.pydev.refactoring.tests.ast.factory.PyAstFactoryWithPrettyPrinting

package org.python.pydev.refactoring.tests.ast.factory;

import org.python.pydev.parser.jython.ast.Expr;
import org.python.pydev.parser.jython.ast.Module;
import org.python.pydev.parser.jython.ast.Return;
import org.python.pydev.parser.jython.ast.exprType;
import org.python.pydev.parser.prettyprinter.AbstractPrettyPrinterTestBase;
import org.python.pydev.parser.prettyprinterv2.MakeAstValidForPrettyPrintingVisitor;

import com.aptana.shared_core.callbacks.ICallback;

public class PyAstFactoryWithPrettyPrinting extends AbstractPrettyPrinterTestBase {

    public static void main(String[] args) {
        try {
            DEBUG = true;
            PyAstFactoryWithPrettyPrinting test = new PyAstFactoryWithPrettyPrinting();
            test.setUp();
            test.testVarious22();
            test.tearDown();
            System.out.println("Finished");
            junit.textui.TestRunner.run(PyAstFactoryWithPrettyPrinting.class);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public void testVarious22() throws Throwable {
        final String s = "" +
                "\n" +
                "\n" +
                "\n" +
                "[\n" +
                "    1, \n" +
                "    2,\n" +
                "    self.call(*a)\n" +
                "]\n"
                +
                "\n" +
                "";

        final String expected = "return [1,2,self.call(*a)]\n";

        checkWithAllGrammars(new ICallback<Boolean, Integer>() {

            public Boolean call(Integer version) {
                Module module = (Module) parseLegalDocStr(s);
                exprType value = ((Expr) module.body[0]).value;
                Return node = new Return((exprType) value.createCopy());
                try {
                    MakeAstValidForPrettyPrintingVisitor.makeValid(node);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                String makePrint = makePrint(prefs, node);
                assertEquals(expected, makePrint);
                return true;
            }
        });
    }
}
TOP

Related Classes of org.python.pydev.refactoring.tests.ast.factory.PyAstFactoryWithPrettyPrinting

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.